<?php


namespace app\management\common;


use app\management\model\Copy;
use app\management\model\EveryTimes;
use app\management\model\User;

class IndexCommon
{

    /*
     * @return string
     * 域名列表
     * 域名列表   填写域名数据库   不给自己找麻烦
     * 访问次数    聚合
     * 复制次数   集合
     * 查看访问详情
     * 查看复制详情
     */
    public function getUrlList(){
        $userData = get_admin_session();
        $user = new User();
        $res = $user->where('id',$userData['id'])->find();
        
        $domian  = $res->user_domain;
        if (is_null($domian)){
            return lay_msg(1,'暂无数据',0);
        }
        $copy = new Copy();
        $everyTimes = new EveryTimes();

        $sum=array();
        foreach ($res->user_domain as $k=>$v){
            $sum[$k]['id'] = $k;
            $sum[$k]['domain'] = $v;
            $sum[$k]['copy'] = $copy->where('domain',$v)->count();
            $sum[$k]['everyTimes'] = $everyTimes->where('domain',$v)->count();
            // 计算转化率
            $sum[$k]['conversion'] = (floor(((int)$sum[$k]['copy']/(int)$sum[$k]['everyTimes'])*10000)/10000*100).'%';
        }
//        return $sum;

        return lay_msg(0,'success',count($sum),$sum);
    }

}
